{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "using SymPy\n",
    "using LinearAlgebra"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#  Levi-Civita记号\n",
    "ε= [ (i≠j && i≠k && j≠k )*       #  存在重复指标，取0\n",
    "    (-1)^(sum([i,j,k][σ]>[i,j,k][ρ]   \n",
    "            for σ in 1:3,ρ in  1:3  if σ<ρ) % 2) # 计算逆序数。偶数取1，奇数取-1\n",
    "    for  i in 1:3, j in 1:3, k in 1:3 ] ;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3×3 Array{Int64,2}:\n",
       " -2   0   0\n",
       "  0  -2   0\n",
       "  0   0  -2"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "κ=[sum(ε[l,i,k]*ε[k,j,l] for k in 1:3, l in 1:3) for i in 1:3, j in 1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3×3 Array{Float64,2}:\n",
       " -0.5  -0.0  -0.0\n",
       "  0.0  -0.5  -0.0\n",
       "  0.0   0.0  -0.5"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inv(κ)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3×3 Array{Int64,2}:\n",
       " -2   0   0\n",
       "  0  -2   0\n",
       "  0   0  -2"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "using SymPy\n",
    "using LinearAlgebra\n",
    "\n",
    "#  Levi-Civita记号\n",
    "ε= [ (i≠j && i≠k && j≠k )*       #  存在重复指标，取0\n",
    "    (-1)^(sum([i,j,k][σ]>[i,j,k][ρ]   \n",
    "            for σ in 1:3,ρ in  1:3  if σ<ρ) % 2) # 计算逆序数。偶数取1，奇数取-1\n",
    "    for  i in 1:3, j in 1:3, k in 1:3 ] ;\n",
    "\n",
    "# 计算嘉当度规\n",
    "κ=[sum(ε[l,i,k]*ε[k,j,l] for k in 1:3, l in 1:3) for i in 1:3, j in 1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "UndefVarError: @var not defined",
     "output_type": "error",
     "traceback": [
      "UndefVarError: @var not defined",
      ""
     ]
    }
   ],
   "source": [
    "@var x y z real=true\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 1.4.1",
   "language": "julia",
   "name": "julia-1.4"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.4.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
